using System;
using System.Collections.Generic;
using System.Text;

namespace Crank.Core.Strings
{
    class NounResolver
    {
        PluralizationAssumption lean;

        public NounResolver(PluralizationAssumption lean)
        {
            this.lean = lean;
        }

        public bool CanResolve(Noun left, Noun right)
        {
            return left.ResolvesWith(right);
        }

        protected Noun Resolve(Noun left, Noun right)
        {
            if (left.Equals(right))
                return left.Clone() as Noun;
            else if (left.Singular.Equals(right.Plural))
                return (lean == PluralizationAssumption.AssumeSingular ? right.Clone() : left.Clone()) as Noun;
            else if (right.Singular.Equals(left.Plural))
                return (lean == PluralizationAssumption.AssumeSingular ? left.Clone() : right.Clone()) as Noun;
            else
                throw new InvalidOperationException("Cannot Resolve these Nouns");
        }

        public Noun TryResolve(Noun left, Noun right)
        {
            if (CanResolve(left, right))
                return Resolve(left, right);
            return null;
        }
    }
}
